package com.aaa.javaweb.servlet;

import com.aaa.javaweb.dao.RoomTypeDao;
import com.aaa.javaweb.entity.RoomType;
import com.aaa.javaweb.entity.Roomtypelike;
import com.aaa.javaweb.until.TableLabe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import java.util.List;
import java.util.Map;

@Controller
public class RoomTypeController {

    @Autowired
    private RoomTypeDao roomDao;


    @RequestMapping("selectroom")
    @ResponseBody
    public TableLabe selectroom(Roomtypelike roomtypelike){
        List<Map> maps = roomDao.selectAll(roomtypelike);
        int count = roomDao.selcount();
        if(maps!=null && maps.size()>0){
            TableLabe tableLabe = new TableLabe(0,"",count,maps);
            return tableLabe;
        }else {
            return null;
        }

    }


    @RequestMapping("delone")
    @ResponseBody
    public int deleteone(int id){
        int delone =roomDao.delone(id);
        return delone;
    }

    @RequestMapping("roomtype")
    @ResponseBody
    public List<Map> selroomtype(){
        List<Map> roomtype = roomDao.selroomtype();
        return roomtype;
    }

    @RequestMapping("tjone")
    @ResponseBody
    public int tianjia(RoomType room){
        int tianjia = 1;
        String s = room.getRoomcode().toString();
        List<Map> selroomcode =roomDao.selroomcode();
        for (Map map : selroomcode) {
            if (map.get("roomcode").equals(s)){
                tianjia = 0;
                System.out.println("11111");
                break;
            }
        }
        if (tianjia==0){
            return 0;
        }else {
            tianjia = roomDao.tianjia(room);
            return tianjia;
        }

    }



}
